/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef DEVICES_E28_H
#define DEVICES_E28_H

/* Includes ------------------------------------------------------------------*/
#include "Devices_E28_Config.h"
#include "usart.h"
#include "stdbool.h"
#include "string.h"
/* Exported constants --------------------------------------------------------*/
#define E28_ReceiveLength 30

/* Exported macros -----------------------------------------------------------*/
#pragma anon_unions
#define E28_FucGroundInit \
{ \
	&E28_USART_IT_Init, \
	&E28_BaseInit, \
	&E28_GetStateCommand, \
	&E28_GetIrqStatus, \
	&E28_ClearIrqStatus, \
	&E28_Tx_Transmit, \
	&E28_Rx_Set, \
	&huart3, \
}

/* Exported types ------------------------------------------------------------*/
typedef enum
{
	/* GetStateCommand */
	GetStateCommand = 0xC0,
	
	/* Write Register */
	WriteRegister = 0x18,
	
	/* Read Register */
	ReadRegister = 0x19,//
	
	/* Set Standby Mode */
	SetStandby = 0x80,
	
	/* Set Packet Type */
	SetPacketType = 0x8A,
	
	/* Set Rf Frequency */
	SetRfFrequency = 0x86,
	
	/* Set Buffer Base Address */
	SetBufferBaseAddress = 0x8F,
	
	/* Set Modulation Params */
	SetModulationParams = 0x8B,
	
	/* Set PacketParams */
	SetPacketParams = 0x8C,
	
	/* Set TxParams */
	SetTxParams =0x8E,
	
	/* Write Buffer */
	WriteBuffer = 0x1A,
	
	/* Set DioIrq Params */
	SetDioIrqParams = 0x8D,
	
	/* Set Tx */
	SetTx = 0x83,
	
	/* Set Rx */
	SetRx = 0x82,
	
	/* Get Rx Buffer Status */
	GetRxBufferStatus = 0x17,//
	
	/* Get Irq State */
	GetIrqState = 0x15,//
	
	/* Clear Irq State */
	ClearIrqState = 0x97,//
	
}E28_ModeOpcode;


typedef struct
{
	union
	{
		uint8_t StateValue;
		struct
		{
			E28State_Busy_t 	 BUSY :1;
			uint8_t 					 Reserved :1;
			E28State_Command_t CommandState :3;
			E28State_Circuit_t CircuitMode :3;
		}E28_StateBit;
	};
}E28State_t;


typedef struct
{
	union
	{
		uint16_t IrqValue;
		struct
		{
			bool TxDoneFlag 											: 1;
			bool RxDoneFlag 											: 1;
			bool SyncWordValidFlag 								: 1;
			bool SyncWordErrorFlag 								: 1;
			bool HeaderValidFlag									: 1;
			bool HeaderErrorFlag									: 1;
			bool CrcErrorFlag											: 1;
			bool RangingSlaveResponseDoneFlag 		: 1;
			bool RangingSlaveRequestDiscardFlag		: 1;
			bool RangingMasterResultValidFlag			: 1;
			bool RangingMasterTimeoutFlag		      : 1;		
			bool RangingMasterRequestValidFlag		: 1;
			bool CadDoneFlag											: 1;
			bool CadDetectedFlag									: 1;
			bool RxTxTimeoutFlag									: 1;
			bool PreaDetected_AdvRanging_Done			: 1;
		};
	};
}E28IrqState_t;





typedef struct
{
	void(*E28_USART_IT_Init)(UART_HandleTypeDef* huartx);
	void(*E28_BaseInit)(void);
	void(*E28_GetStateCommand)(void);
	void(*E28_GetIrqStatus)(void);
	void(*E28_ClearIrqStatus)(uint16_t IrqMaskClear);
	void(*E28_Tx_Transmit)(SX1280_Offset_t Offset, \
													uint16_t* Buffer, \
													uint8_t BufferLength);
	void(*E28_Rx_Set)(SX1280_PeriodBaseCount_t ReceiveMode);
	UART_HandleTypeDef* USARTRegister_Hook;
}E28_Fuc;
/* Exported variables --------------------------------------------------------*/
extern E28_Fuc E28_Functions;
extern E28State_t E28State;
extern uint16_t E28_Receive[E28_ReceiveLength];
/* End -----------------------------------------------------------------------*/
#endif
